<template>

    <div>

        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="ID">
            </el-table-column>
            <el-table-column
                    label="姓名">
                <template slot-scope="scope">
                    {{user.username}}
                </template>
            </el-table-column>
            <el-table-column
                    label="文件名称">
                <template slot-scope="scope">
                    {{scope.row.wangpanFile.name}}
                </template>
            </el-table-column>
            <el-table-column
                    prop="expireTime"
                    label="过期时间">
            </el-table-column>
            <el-table-column
                    prop="state"
                    label="状态">
            </el-table-column>
            <el-table-column
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="delOne(scope.row.id)">删除</el-button>
                    <el-button @click="cancleShare(scope.row.id)" v-if="scope.row.state=='分享中'">取消分享</el-button>
                </template>
            </el-table-column>
        </el-table>

    </div>




</template>

<script>
    export default {
        name: "myshare",
        data(){
            return {
                user:{},
                tableData:[]
            }
        },
        watch:{
        },
        methods:{
            delOne(id){
                this.$confirm('此操作将永久删除该分享, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.axios.post(`/wangpanshare/share-info/deleteOne?id=`+id).then(res=>{
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.initData();
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            cancleShare(id){
                this.$confirm('确定取消分享, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.axios.post(`/wangpanshare/share-info/cancleShare?id=`+id).then(res=>{
                        this.$message({
                            type: 'success',
                            message: '取消成功!'
                        });
                        this.initData();
                    })

                }).catch(() => {
                });
            },
            initData(){
                this.axios.post("/wangpanshare/share-info/list?uid="+this.user.id).then(res=>{
                    this.tableData = res.data;
                })

            }

        },
        created(){
            let user = localStorage.getItem("wangpan_user");
            if(!user){
                this.$message.error("请先去登录")
                setTimeout(()=>{
                    this.$router.push("/")
                },1500)
            }else{
                this.user = JSON.parse(user);
                this.initData()
            }
        }

    }
</script>

<style scoped>

</style>
